//bench.js
const app = getApp()
var lanya = require("../../utils/BLELocker.js");
const util = require('../../utils/util.js')
const lbbService = require('../service/service.js')

Page({
  data: {
    
  },

  onLoad: function (options) {
    
    let that = this;
    wx.setNavigationBarTitle({
      title: util.CONST_DATA.VERSION,
    })
  },
  
  onReady: function () {
    // Do something when page ready.
    let that = this
    that.toast = that.selectComponent("#toast")
    that.personalModal = that.selectComponent("#personalModal")
    if(!app.globalData.windowHeight){
      wx.getSystemInfo({
        complete: (res) => {
          app.getWindowHeight(res);
          that.setData({
            scrollHeight:app.getScrollHeight(200)
          })
        },
      })
    }
  },
  onShow: function () {
    let that = this;
    if(!that.data.authList||that.data.authList.length==0){
      that.getAuthList();
    }
    if(!that.data.isSign){
      that.getIsSign();
    }
    // Do something when page show.
  },
  onHide: function () {
    // Do something when page hide.
  },
  onUnload: function () {
    // Do something when page close.
  },
  getDemanNumber(){
    let that = this;
    lbbService.getPendingDemandNum({},function(res){
        that.setData({
            demandNum:res.data
        })
    })
  },
  /**
   * 获取权限列表
   */
  getAuthList:function(){
    let that = this;
    lbbService.getAuthList({},function(res){
      that.setData({
        authList: res.data
      })
      let list = res.data.map(item =>item.btn_pinyin)
      if(list.includes('demand-to-processed')){
          lbbService.getPendingDemandNum({},function(res){
              that.setData({
                demandNum:res.data
              })
          })
      }
    })
  },
  getIsSign: function(){
    let that = this;
    lbbService.getIsSign({},res=>{
      util.print('getIsSign',res.data);
      if(res.data){
        that.setData({
          isSign:true
        })
      }else {
        that.personalModal.showModal('您今天还未打卡，请先打卡', that.toSign);
      }
    })
  },
  toSign:function(){
    wx.navigateTo({
      url: '../SCM/signIn/clockIn/selectReason/selectReason?onDuty='+1,
    })
  }
})